package main

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	engine := gin.Default()

	engine.GET("/hellojson", func(context *gin.Context) {
		path := "请求路径:" + context.FullPath()
		fmt.Println(path)

		context.JSON(http.StatusOK, gin.H{
			"code":    1,
			"message": "OK",
			"data":    path,
		})
	})

	engine.GET("/jsonstruct", func(context *gin.Context) {
		path := "请求路径:" + context.FullPath()
		fmt.Println(path)

		resp := Response{Code: 1, Message: "OK", Data: path}

		context.JSON(http.StatusOK, &resp)
	})

	engine.Run()
}

type Response struct {
	Code    int         `json:"code" xml:"code" form:"code" binding:"code,required"`
	Message string      `json:"message" xml:"message" form:"message" binding:"message,required"`
	Data    interface{} `json:"data" xml:"data" form:"data" binding:"data,required"`
}
